<?php


namespace App\Modules\Admin\Services\System;


use App\Exceptions\Exception;
use App\Modules\Admin\Services\BaseService;
use App\Modules\Admin\Entities\System\Area as AreaModel;
use Illuminate\Support\Facades\DB;

class AreaServices  extends BaseService
{
    public function __construct(AreaModel $areaModel)
    {
        $this->model = $areaModel;
    }

    /**
     * 菜单列表
     *
     * @param array $params
     * @return array
     */
    public function lists(array $params) : array
    {
        $lists = $this->model->get();
        return list_to_tree($lists->toArray(),'id','parent_id');
    }

    public function getSelectLists($request)
    {

       return $this->model->getSelectLists();
    }
    public function update(array $params)
    {
        DB::beginTransaction();
        try{
            parent::update($params); // TODO: Change the autogenerated stub
            DB::commit();
            return true;
        }catch (Exception $e){
            DB::rollBack();
            $this->setError($e->getMessage());
            return false;
        }
    }
}